/*
 * @lc app=leetcode.cn id=20 lang=cpp
 *
 * [20] 有效的括号
 */
#include <iostream>
#include <stack>
#include <string>
#include <unordered_map>

using std::cout;
using std::endl;
using std::stack;
using std::string;
using std::unordered_map;
// @lc code=start
class Solution
{
  public:
    bool isValid(string s)
    {
        unordered_map<char, char> my_map;
        stack<char> my_stack;
        my_map['('] = ')';
        my_map['{'] = '}';
        my_map['['] = ']';

        for (char ch : s) {
            if (my_stack.empty()) {
                my_stack.push(ch);
            } else {
                if (my_map[my_stack.top()] == ch) {
                    my_stack.pop();
                } else {
                    my_stack.push(ch);
                }
            }
        }

        if (my_stack.empty()) {
            return true;
        }
        return false;
    }
};
// @lc code=end

int main()
{
    string str("()");
    Solution s;
    std::cout << s.isValid(str) << " " << std::endl;
    std::cout << str;
}
